package org.an.demo.test;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.widget.RemoteViews;
import org.an.demo.R;
import org.an.ku.view.notification.LKNotificationBar;

/**
 * Created by Fcy on 2016/10/15.<br/>
 */
public class RoundViewActivity extends FragmentActivity
  implements LKNotificationBar.NotificationTouchListener {
  private FragmentActivity mContext = this;

  //@Override protected boolean openSwipeBack() {
  //  return true;
  //}

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_roundview);

    //RoundTextView rtv_2 = (RoundTextView) findViewById(R.id.rtv_2);
    //rtv_2.setOnLongClickListener(new View.OnLongClickListener() {
    //  @Override public boolean onLongClick(View v) {
    //    Toast.makeText(mContext, "LongClick--->RoundTextView_2", Toast.LENGTH_SHORT).show();
    //    return false;
    //  }
    //});
    //
    //final RoundTextView rtv_3 = (RoundTextView) findViewById(R.id.rtv_3);
    //rtv_3.setOnClickListener(new View.OnClickListener() {
    //  @Override public void onClick(View v) {
    //    RoundViewDelegate delegate = rtv_3.getDelegate();
    //    delegate.setBackgroundColor(
    //      delegate.getBackgroundColor() == Color.parseColor("#ffffff") ? Color.parseColor("#F6CE59")
    //        : Color.parseColor("#ffffff"));
    //  }
    //});
  }

  @Override public void onNotificationTouch(LKNotificationBar bar) {

  }

  public void onClick(View view) {
    ////Toast.makeText(mContext, "Click--->RoundTextView_1", Toast.LENGTH_SHORT).show();
    //LKNotification.show(mContext, "标题", "这个是内容哦", R.drawable.bg, RoundViewActivity.this);
    //Intent intent = new Intent("com.homelink.im.LEANCLOUD_PUSH");
    //String json = RawUtils.getString(this, R.raw.data);
    //intent.putExtra("com.avos.avoscloud.Data", json);
    //sendBroadcast(intent);

    noti();
  }

  public void noti() {
    Intent intent = new Intent();
    PendingIntent pendingIntent =
      PendingIntent.getBroadcast(this, 1000, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setSmallIcon(R.drawable.icon)
      .setContentTitle("title")
      .setContentText("contentText")
      .setNumber((int) (Math.random() * 1000))
      //.setTicker()
      //must set pendingintent for this notification, or will be crash
      .setContentIntent(pendingIntent)
      .setDefaults(
        Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
      .setAutoCancel(true)
      .setWhen(0);
    Notification notification = mBuilder.build();
    if (Build.VERSION.SDK_INT >= 21) {
      // 需要打开 通知的悬浮通知权限
      RemoteViews headsUpView =
        new RemoteViews(getPackageName(), R.layout.layout_headsup_notification);
      notification.priority = Notification.PRIORITY_MAX;
      notification.headsUpContentView = headsUpView;
    }
    NotificationManager notificationManager =
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(12, notification);
  }
}
